from utility.sql_helper import MysqlHelper


class Problems(object):
    def __init__(self):
        self._sql = MysqlHelper()

    def get_problems(self, problem_level, keyword):
        sql = "SELECT * FROM problems WHERE problem_title LIKE %s"
        params = '%'+keyword+'%'
        if problem_level != '':
            sql += ' AND problem_level=%s'
            params = ('%'+keyword+'%', problem_level)
        sql += ';'
        list_data = self._sql.get_all(sql, params)
        return list_data

    def get_problem_detail(self, problem_id):
        sql = 'SELECT * FROM problems WHERE problem_id=%s;'
        params = problem_id
        list_data = self._sql.get_all(sql, params)
        return list_data

    def get_examples(self, problem_id):
        sql = 'SELECT * FROM examples WHERE problem_id=%s;'
        params = problem_id
        list_data = self._sql.get_all(sql, params)
        return list_data

